﻿using System;
using System.Collections;

namespace ProgressSpace
{
    public enum ProgressResult { TaskComplete, Cancel }

    public interface IProgressPresenter
    {
        ProgressResult Show ();
        void SetMeter (int percent);
        void SetText (string message);
        void Close ();
    }

    public class ProgressModelView
    {
        public string Title { get; protected set; }
    }

    public class ProgressModel : ProgressModelView
    {
        private IProgressPresenter progressPresenter;

        public ProgressModel (string title)
        {
            this.Title = title;
        }

        public IProgressPresenter Presenter
        {
            private get { return progressPresenter; }
            set
            {
                if (progressPresenter != null)
                    throw new InvalidOperationException ("Presenter already assigned");
                progressPresenter = value;
            }
        }

        public void SetMeter (int percent)
        { Presenter.SetMeter (percent); }

        public string Caption
        { set { Presenter.SetText (value); } }

        public ProgressResult Show ()
        {
            if (Presenter == null)
                return ProgressResult.TaskComplete;

            {
                ProgressResult result = Presenter.Show ();
                return result;
            }

        }

        public void Dismiss ()
        {
            Presenter.Close ();
        }
    }
}
